<template>
	<a-layout>
		<y-form radius="radius" :keys="columns" v-model="info" @submit="submit" />
	</a-layout>
</template>

<script>
	import yForm from "@/y-ui/y-form/y-form.vue";
	export default {
		components: {
			yForm
		},
		data() {
			return {
				placeholder: '开始输入...',
				info: {

				},
				tabs: [{
					msgTypeCode: 'CLASS_NOTICE_APP',
					msgTypeDesc: "班级通知",
					//选择班级
					columns: [{

					}]
				}, {
					msgTypeCode: 'SCHOOL_NOTICE_APP',
					msgTypeDesc: "学校通知",
				}, {
					msgTypeCode: 'MEETING__NOTICE_APP',
					msgTypeDesc: "会议通知",
					columns: []
				}]
			}
		},
		computed: {
			columns() {
				return [{
						type: 'yPicker',
						key: 'msgTypeCode',
						lable: '栏目：',
						placeholder: '请选择',
						range: this.tabs,
						rangeKey: 'msgTypeDesc',
						valueKey: 'msgTypeCode',
						change(e, {
							key,
							range,
							rangeKey
						} = {}, v) {
							if (!v) return;
							range.map(x => {
								if (x[key] === e) {
									v[rangeKey] = x[rangeKey];
								}
							});
						},
						rules: {
							rule: ['required'],
							msg: ['请选择']
						}
					},
					{
						type: 'yInput',
						key: 'title',
						lable: '标题：',
						rules: {
							rule: ['required'],
							msg: ['请填写']
						}
					}, {
						type: 'yInput',
						key: 'subTitle',
						lable: '描述：',
						rules: {
							rule: ['required'],
							msg: ['请填写']
						}
					}, {
						// type: 'editor',
						key: "content",
						lable: "内容：",
						block: true
					},
					// {
					// 	type: 'yRadio',
					// 	key: 'yRadio',
					// 	lable: '发送范围：',
					// 	rangeKey: 'name',
					// 	valueKey: 'value',
					// 	range: [{
					// 			value: '1',
					// 			name: '全校师生'
					// 		},
					// 		{
					// 			value: '2',
					// 			name: '教师'
					// 		},
					// 		{
					// 			value: '3',
					// 			name: '学生'
					// 		}
					// 	],
					// 	rules: {
					// 		rule: ['required'],
					// 		msg: ['必选']
					// 	}
					// },
				];
			}
		},
		methods: {
			submit(e) {
				if (!e) return;
				this.$http.post('/api/v1/bMessage/insertOne', { ...this.info
				}).then(res => {
					uni.showToast({
						duration: 1500,
						title: "提交成功"
					});
					setTimeout(e => {
						uni.redirectTo({
							url: './notice'
						})
					}, 1000);
				}).finally(this.$loading({
					msg: '提交中'
				}));
			}
		}
	};
</script>
